﻿using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Model;
using Model.eums;

namespace Utils.UserHelper;

public class AdminChangeUserAuth
{
    public static async Task<bool> ChangeUserAuth(string account,Auth auth)
    {
        if (UserLogin.LoginUser != null && UserLogin.LoginUser.Auth != Auth.Admin)
            return false;
        await using var db = new DataDbContent();
        var userInfo = await db.LoginUser.FirstOrDefaultAsync(
                e => e.Account == account);
        if (userInfo == null)
            return false;
        userInfo.Auth = auth;
        await db.SaveChangesAsync();
        return true;
    }
}